"""
写添加日志页面的信息
"""
from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select
class RztjPage(BasePage):
    url = ("http://192.168.1.55/crm/index.php?m=log&a=mylog_add")
    bt_locator = (By.NAME, "subject")

    sj_locator = (By.ID, "business_name")
    # 清楚数据定位表格
    tbody_locator = (By.XPATH, '//*[@id="data"]')
    sj_ok_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]')

    rw_locator = (By.ID, "task_name")
    # 清楚数据定位表格
    tbody_locator = (By.XPATH, '//*[@id="data"]')
    rw_ok_locator = (By.XPATH, '/html/body/div[8]/div[3]/div/button[1]')

    cp_locator = (By.ID, "product_name")
    # 清楚数据定位表格
    tbody_locator = (By.XPATH, '//*[@id="data"]')
    yxcp_ok_locator = (By.XPATH, '/html/body/div[9]/div[3]/div/button[1]')

    miaosu_locator = (By.CSS_SELECTOR, ".ke-edit-iframe")
    baocun_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]")
    def bt_input(self,title):
        """标题输入框"""
        self.driver.find_element(*self.bt_locator).clear()
        self.driver.find_element(*self.bt_locator).send_keys(title)
    def sj_click(self,sjname):
        """商机选择框"""
        self.driver.find_element(*self.sj_locator).click()
        tbody = self.driver.find_element(*self.tbody_locator)
        trs = tbody.find_elements(By.TAG_NAME, "tr")
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == sjname:
                tds[0].find_element(By.CSS_SELECTOR, 'input[name="business"]').click()
                break
        self.driver.find_element(*self.sj_ok_locator).click()
    def rw_click(self,rwname):
        """任务选择框"""
        self.driver.find_element(* self.rw_locator).click()
        tbody =  self.driver.find_element(*self.tbody_locator)
        trs = tbody.find_elements(By.TAG_NAME, "tr")
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == rwname:
                tds[0].find_element(By.CSS_SELECTOR, 'input[name="task_id"]').click()
                break
        self.driver.find_element(*self.rw_ok_locator).click()
    def cp_click(self,cpname):
        """产品输入框"""
        self.driver.find_element(*self.cp_locator).click()
        tbody = self.driver.find_element(*self.tbody_locator)
        trs = tbody.find_elements(By.TAG_NAME, "tr")
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == cpname:
                tds[0].find_element(By.CSS_SELECTOR, 'input[name="product_id"]').click()
                break
        self.driver.find_element(*self.yxcp_ok_locator).click()

    def miaosu_input(self,content):
        """描述输入框"""
        self.driver.find_element(*self.miaosu_locator).send_keys(content)
    def baocun_click(self):
        """点击保存"""
        self.driver.find_element(*self.baocun_locator).click()

    def open(self):
        """打开页面地址"""
        self.driver.get(self.url)